﻿<?php
class QuotationsController extends AppController {
	var $name = 'Quotations';
	var $helpers = array('Html','Ck');
	var $components = array('Init', 'Param');
        var $uses = array('Picture');

	function beforeFilter() {
            if (!$this->Session->read('admin')) {
                $this->redirect('/users/login');
            }
            else {
                $this->Init->startup($this);
                $this->Admin = $this->Init->init();

                $this->set('dashboard',0);
                $this->set('content',0);
                $this->set('products',1);
                $this->set('component',0);
                $this->set('system',0);

                $this->set('title',__('Quotations Management', true));
                $this->set('sub_title', $this->Param->getAction($this->params));
            }
	}

	function index() {
            $pictures = $this->Picture->find('all', array(
                'conditions' => array(
                        'Picture.status' => 1,
                        'Picture.kind' => 6
                        ),
                'order' 	 => array('Picture.sort desc','Picture.date desc')
            ));
            $this->set('pictures',$pictures);
            $this->render('index');
	}
        
        function edit($id = null) {
            $this->helpers[] = 'Ck';
            $id = $this->Param->getID($this->params);

            if (isset($this->data)) {
                    $this->data['Picture']['date'] = date('Y-m-d');
                    $this->data['Picture']['kind'] = 1;
                    if ($this->data['Picture']['image'] != "") {
                        App::import('Component', 'Upload');
                        $file = new UploadComponent();
                        if ($file->checkSize($this->data['Picture']['image']['size']) && $file->getFileExtension($this->data['Picture']['image']['name'])== 'pdf') {
                            $_file = $file->upload($this->data['Picture']['image']);
                            $this->data['Picture']['image_link'] = $_file;
                            if ($this->Picture->save($this->data)) {
                                $this->Session->setFlash('Done successfully!');
                                $this->redirect('/banner');
                            }
                        }
                    }
            }
            else {
                    if (isset($id) && ($id > 0)) {
                        $this->data = $this->Picture->find('first',array(
                                'conditions' => array('Picture.id' => $id)
                        ));
                    }
            }
	}


	function del($id = null) {
            $this->loadModel('Picture');
            $id = $this->Param->getID($this->params);
            $this->Picture->id = $id;
            $this->Picture->delete($id);
            $this->Session->setFlash('Done successfully!');
            $this->redirect('/inside_banner');
	}
}
?>
